package com.szholly.utils.spring.springmvc.route;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.servlet.HandlerExecutionChain;
import org.springframework.web.servlet.handler.AbstractHandlerMapping;
import org.springframework.web.util.UrlPathHelper;

/**
 * 定义功能注册下的功能导航
 *
 */
public class CustomHandlerMapping extends AbstractHandlerMapping {

	private RouteHandler formController;
	private UrlPathHelper urlHelper;

	public CustomHandlerMapping() {
		formController = new RouteHandler();
		urlHelper = new UrlPathHelper();
	}

	@Override
	protected Object getHandlerInternal(HttpServletRequest request)
			throws Exception {
		// ��ȡURL
		String url = urlHelper.getLookupPathForRequest(request);
		url = url.replace(".do", "");
		if (url.startsWith("/")) {
			url = url.substring(1);
		}
		if (RouteController.Routes.containsKey(url)) {
			HandlerExecutionChain chain = new HandlerExecutionChain(
					formController);
			return chain;
		}
		return null;
	}
}